package com.wly
{
	import com.wly.datapool.define.GlobalDefine;
	import com.wly.ui.panel.GlobalInfoPanel;
	
	import flash.display.MovieClip;

	public class PanelManager extends MovieClip
	{
		static private var _instance:PanelManager;
		
		private var _curPanel:MovieClip;
		private var _globalInfoPanel:GlobalInfoPanel;
		
		public function PanelManager()
		{
			super();
			_instance = this;
		}
		
		static public function getInstance():PanelManager
		{
			return _instance;
		}
		
		public function showPanel(panel:MovieClip, x:int=0, y:int=0):void
		{
			removePanel(_curPanel);
			if(panel)
			{
				_curPanel = panel;
				_curPanel.x = x;
				_curPanel.y = y;
				addChild(_curPanel);
			}
		}
		
		public function showPenelCenter(panel:MovieClip):void
		{
			removePanel(_curPanel);
			if(panel)
			{
				_curPanel = panel;
				_curPanel.x = GlobalDefine.MAP_WIDTH/2;
				_curPanel.y = GlobalDefine.MAP_HEIGHT/2;;
				addChild(_curPanel);
			}
		}
		
		public function removePanel(panel:MovieClip):void
		{
			if(_curPanel && _curPanel==panel)
			{
				removeChild(_curPanel);
				_curPanel = null;
			}
		}
		
		public function showGlobalInfo():void
		{
			_globalInfoPanel = new GlobalInfoPanel();
			_globalInfoPanel.updateData();
			addChildAt(_globalInfoPanel, 0);
		}
		
		public function removeGlobalInfoPanel():void
		{
			if(_globalInfoPanel)
			{
				removeChild(_globalInfoPanel);
			}
		}
	}
}